/*
 * Block.cpp
 *
 *  Created on: 27.08.2010
 *      Author: skuld
 */

#include "Block.h"
#include "Window.h"
Window window;
Block::Block() {
	// Initialize offsets
	x = 0;
	y = 0;

	// Initialize velocity
	xVel = 0;
	yVel = 0;
}

void Block::handleInput() {
	// If a key was pressed
	if(event.type == SDL_KEYDOWN)
	{
		switch(event.key.keysym.sym)
		{
		// Adjust the velocity
				case SDLK_UP:
					yVel -= 45;
					break;

				case SDLK_DOWN:
					yVel += 45;
					break;

				case SDLK_LEFT:
					xVel -= 90;
					break;

				case SDLK_RIGHT:
					xVel += 90;
					break;
		}
	}
	// If a key was released
	else if(event.type == SDL_KEYUP)
	{
		switch(event.key.keysym.sym)
				{
				// Adjust the velocity
						case SDLK_UP:
							yVel += 45;
							break;

						case SDLK_DOWN:
							yVel -= 45;
							break;

						case SDLK_LEFT:
							xVel += 90;
							break;

						case SDLK_RIGHT:
							xVel -= 90;
							break;
				}
	}
}

void Block::move()
{
	// Move the block left or right
	x += xVel;

	// If the dot went too far to the left or right
	if((x < 0) || (x + 180 > 800))
	{
		// move back
		x -= xVel;
	}

	// Move the block up or down
	y += yVel;

	// If the dot went too far
	if((y < 0) || (y + 90 > 600))
	{
		// move back
		y -= yVel;
	}
}

void Block::show()
{
	// show the block
}

